<%--
  Created by IntelliJ IDEA.
  User: 75880
  Date: 2024/8/17
  Time: 22:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>

<head>
    <%
        String base = request.getContextPath() + "/";
        String url = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + base;
    %>
    <base href="<%=url%>">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>供应商管理系统</title>
    <meta name="description" content="这是一个 index 页面">
    <meta name="keywords" content="index">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/i/favicon.png">
    <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png">
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <link rel="stylesheet" href="assets/css/amazeui.min.css"/>
    <link rel="stylesheet" href="assets/css/admin.css">
    <link rel="stylesheet" href="assets/css/app.css">
</head>

<body data-type="generalComponents">
<header class="am-topbar am-topbar-inverse admin-header">
    <div class="am-collapse am-topbar-collapse" id="topbar-collapse">
        <ul class="am-nav am-nav-pills am-topbar-nav am-topbar-right admin-header-list tpl-header-list">
            <li class="am-dropdown" data-am-dropdown data-am-dropdown-toggle>
                <a class="am-dropdown-toggle tpl-header-list-link" href="javascript:;">
                    <span id="yonghuming" class="tpl-header-list-user-nick"></span><span class="tpl-header-list-user-ico"> <img
                        src="assets/img/user06.png"></span>
                </a>
                <ul class="am-dropdown-content">
                    <li><a href="login.jsp"><span class="am-icon-power-off"></span> 退出</a></li>
                </ul>
            </li>
        </ul>
    </div>
</header>
<div class="tpl-page-container tpl-page-header-fixed">
    <div class="tpl-left-nav tpl-left-nav-hover">
        <div class="tpl-left-nav-list">
            <ul class="tpl-left-nav-menu">
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list">
                        <i class="am-icon-wpforms"></i>
                        <span>企业管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu">
                        <li>
                            <a href="info-certification.jsp">
                                <i class="am-icon-angle-right"></i>
                                <span>企业信息认证</span>
                            </a>
                        </li>
                    </ul>
                </li>
                <li class="tpl-left-nav-item">
                    <a href="javascript:;" class="nav-link tpl-left-nav-link-list active">
                        <i class="am-icon-table"></i>
                        <span>供应商管理</span>
                        <i class="am-icon-angle-right tpl-left-nav-more-ico am-fr am-margin-right tpl-left-nav-more-ico-rotate"></i>
                    </a>
                    <ul class="tpl-left-nav-sub-menu" style="display:block">
                        <li>
                            <a href="white-list.jsp">
                                <i class="am-icon-angle-right"></i>
                                <span>供应商白名单</span>
                            </a>
                            <a href="black-list.jsp" class="active">
                                <i class="am-icon-angle-right"></i>
                                <span>供应商黑名单</span>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </div>
    </div>
    <div class="tpl-content-wrapper">
        <div class="tpl-content-page-title">
            供应商黑名单列表
        </div>
        <ol class="am-breadcrumb">
            <li class="am-active"><a style="color: #999999;">供应商管理</a></li>
            <li class="am-active">供应商黑名单</li>
        </ol>
        <div class="tpl-portlet-components">
            <div class="tpl-block">
                <div class="am-g">
                    <div class="am-u-sm-6 am-u-md-2">
                        <div class="am-input-group am-input-group-sm">
                                <span class="am-input-group-btn">
                                    <span style="font-size: 14px;margin-right: 8px;margin-left: 8px">企业名称</span>
                                </span>
                            <input name="企业名字"  type="text" class="am-form-field"
                                   placeholder="&nbsp;&nbsp;请输入企业名称"
                                   style="border: 1px solid #c2cad8;border-radius: 3px;">
                        </div>
                    </div>

                    <div style="float:right">
                        <div class="am-form-group">
                            <button type="button" class="am-btn am-btn-primary am-btn-sm"
                                    id="doc-prompt-toggle" name="kk">添加供应商
                            </button>
                        </div>
                    </div>
                    <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
                        <div class="am-modal-dialog">
                            <form action="" class="am-form am-form-horizontal">
                                <legend style="font-size: 18px;padding: 12px 0;">添加供应商</legend>
                                <div class="am-form-group">
                                    <label for="doc-select-1" class="am-u-sm-4 am-form-label"
                                           style="font-size: 15px;">企业名称</label>
                                    <div class="am-u-sm-6">
                                        <select name='sel' id="doc-select-1" required>

                                        </select>
                                    </div>
                                    <span class="am-form-caret"></span>
                                </div>
                                <div class="am-form-group">
                                    <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                           style="font-size: 15px;">统一社会信用代码</label>
                                    <div class="am-u-sm-6" id="xinyongma" style=" text-align: left;margin-top: 6px;" >
                                        <span id="scode"></span>
                                    </div>

                                </div>
                                <div class="am-form-group" style="margin-bottom: 20px;">
                                    <label for="doc-select-2" class="am-u-sm-4 am-form-label"
                                           style="font-size: 15px;">添加理由</label>
                                    <div class="am-u-sm-6">
                                        <textarea class="" rows="4" id="user-intro" placeholder="请输入添加理由"></textarea>
                                    </div>
                                </div>
                            </form>
                            <div class="am-modal-footer" style="border-top: 1px solid #dedede;">
                                <span name=" 取消" class="am-modal-btn" data-am-modal-cancel>取消</span>
                                <span  name="提交" class="am-modal-btn" data-am-modal-confirm>提交</span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="am-g">
                    <div class="am-u-sm-12">
                        <form class="am-form">
                            <table class="am-table am-table-striped am-table-hover table-main">
                                <thead>
                                <tr>
                                    <th class="table-id">序号</th>
                                    <th class="table-title">企业名称</th>
                                    <th class="table-type">企业联系人</th>
                                    <th class="table-author am-hide-sm-only">联系方式</th>
                                    <th class="table-date am-hide-sm-only">联系邮箱</th>
                                    <th class="table-date am-hide-sm-only">添加理由</th>
                                    <th class="table-date am-hide-sm-only">更新日期</th>
                                    <th class="table-set">操作</th>
                                </tr>
                                </thead>
                                <tbody id="doc-modal-list">

                                </tbody>
                            </table>
                            <div class="button">


                            </div>
                            <hr>
                        </form>
                    </div>
                </div>
            </div>
            <div class="tpl-alert"></div>
        </div>
    </div>
</div>

<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script>

    const constAccount = sessionStorage.getItem('constAccount');


    //查询功能，全查条件查并加上按钮
    $(document).ready(function () {
       selectAll();
    });
    function selectAll(){
        var str=$("[name='企业名字']").val();
        $.get("black/query",{"account":constAccount,"str":str},function (ph) {
            JSON.stringify(ph);
            forInfos(ph.list);
            showbuts(ph);
        });


    }
    //
    $(document).on("change","[name='企业名字']",function () {
        selectAll();
    });



    // 解除黑名单

    $(document).on("click","[name='fujiawen']",function () {
        //用供应商名字做id通过企业名字来删除
        var supname=$(this).attr("id");
        $.get("black/delete",{"supname":supname,"account":constAccount},function () {
            selectAll();
        });

    });


    // 添加供应商
    $(function () {
        $('#doc-prompt-toggle').on('click', function () {
            $('#my-prompt').modal({
                relatedTarget: this,
                onConfirm: function (options) {
                    //点击确认调用函数
                    alert("添加成功");
                },
                onCancel: function (e) {
                    //点击取消调用函数
                    alert("用户取消添加");
                }
            });
        });
    });

   $(document).on("click","#doc-prompt-toggle",function () {
       $.get("black/queryEnterprise",{"account":constAccount},function (infos) {
            JSON.stringify(infos);
           $("#doc-select-1").empty();
           $("<option value='-1' disabled >请选择</option>").appendTo("#doc-select-1");
           for (var i=0;i<infos.length;i++){
               $("<option >"+infos[i].name+"</option>").appendTo("#doc-select-1");
           }
       });

   });
    $(document).on("change","[name='sel']",function () {
        var name=$(' #doc-select-1 option:selected').first().val();
        $.get("black/querySocialNo",{"name":name},function (str) {
            JSON.stringify(str);
            $("#xinyongma").empty();
            $("<span>"+str+ "</span>").appendTo("#xinyongma");

        });
    });
    $(document).on("click","[name='提交']",function () {
        var supname = $("#doc-select-1").val();//(添加的供应商的企业名称在下拉列表里的值)
        var  str = $("#user-intro").val();
        $.get("black/add",{"account":constAccount,"str":str,"supname":supname},function () {
            selectAll();
        });


    });
    $(document).on("click","[name='取消']",function () {
           selectAll();

    });
   //遍历信息
    function forInfos(infos) {
        $("tbody").empty();
        for (var i = 0; i < infos.length; i++) {
            $("<tr>" +
                "<td>"+(i+1)+"</td>" +
                "<td>"+infos[i].name+"</td>" +
                "<td>"+infos[i].idcardName+"</td>" +
                "<td class=\"am-hide-sm-only\">"+infos[i].phone+"</td>" +
                "<td class=\"am-hide-sm-only\">"+infos[i].email+"</td>" +
                "<td class=\"am-hide-sm-only\">" +
                "<div class=\"\">" +
                infos[i].reason +
                "</div>" +
                "</td>" +
                "<td class=\"am-hide-sm-only\">"+infos[i].updateDate+"</td>" +
                "<td>" +
                "<div class=\"am-btn-toolbar\">" +
                "<div class=\"am-btn-group am-btn-group-xs\">" +
                " <span  name='fujiawen' id="+infos[i].name+" class=\"am-text-secondary am-icon\"" +
                "  style=\"cursor:pointer\"><span></span >" +
                " 解除黑名单</span>" +
                "</div>" +
                "</div>" +
                "</td>" +
                "</tr>").appendTo("tbody");
        }
    }
    //分页按钮*
    function  showbuts(pageHelper)  {
            $(".button").empty();
        $(".button").empty();
        if(pageHelper.indexPage!=1){
            $("<input type='button' value='首页' name='1' />").appendTo(".button");
            $("<input type='button' value='上一页' name='"+(pageHelper.indexPage-1)+"' />").appendTo(".button");
        }

        if(pageHelper.indexPage!=pageHelper.countPage){
            $("<input type='button' value='下一页' name='"+(pageHelper.indexPage+1)+"' />").appendTo(".button");
            $("<input type='button' value='尾页' name='"+pageHelper.countPage+"' />").appendTo(".button");
        }


    }
    //为分页按钮绑定单击事件
    $(document).on("click","[type='button'][name!='kk']",function () {
        var str=$("[name='企业名字']").val();
        console.log(str);
          var pageindex=$(this).attr("name");
          console.log(pageindex);
          $.get("black/query",{"account":constAccount,"str":str,"pageindex":pageindex},function (ph) {
             JSON.stringify(ph);
               forInfos(ph.list);
               showbuts(ph);
          });

    });
    $(document).ready(function () {
        $.get("UserController/selectUser",{"account":constAccount},function (str) {
            JSON.stringify(str);
            var name =str.name;
            $("#yonghuming").text(name);
        });
    });
</script>
</body>

</html>
